package cn.waka.sys.admin.service;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.waka.sys.admin.object.Result;
import feign.hystrix.FallbackFactory;

public class ApiService {

	@FeignClient(name = "account", fallbackFactory = HystrixClientFallbackFactory.class)
	public static interface VideoService {

		@RequestMapping(value = "/video/index/add/", method = RequestMethod.POST, consumes = "application/json")
		Result add(@RequestParam("id") String id,@RequestParam("title") String title, @RequestParam("img") String img);
		
		@RequestMapping(value = "/video/index/delete/", method = RequestMethod.POST, consumes = "application/json")
		Result delete(@RequestParam("id") String id);
	
	}

	public class PushRemoteServiceFallback implements VideoService {
		@Override
		public Result add(String boxId,String event, String content) {
			Result rs = new Result();
			rs.setCode(-505);
			rs.setMsg("消息服务器出现异常");
			return rs;
		}
		
		@Override
		public Result delete(String boxId) {
			Result rs = new Result();
			rs.setCode(-505);
			rs.setMsg("消息服务器出现异常");
			return rs;
		}
	}
	
	@Component
	static class HystrixClientFallbackFactory implements FallbackFactory<VideoService> {
		@Override
		public VideoService create(Throwable cause) {
			return new VideoService() {

				@Override
				public Result add(String boxId,String event, String content) {
					Result rs = new Result();
					rs.setCode(-505);
					rs.setMsg("消息服务器出现异常");
					return rs;
				}
				
				@Override
				public Result delete(String boxId) {
					Result rs = new Result();
					rs.setCode(-505);
					rs.setMsg("消息服务器出现异常");
					return rs;
				}
				
			};
		}
	}
}
